package com.dyh.quickdemozwei;

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;

/**
 * @Author: yhdong
 * @Date: 2022/1/20 13:11
 */

public class ChildClassLock {
    public static void main(String[] args) {

        Father father = new Child();


        new Thread(()->{
            synchronized (father){
                System.out.println("获取lock成功");
                try {
                    Thread.sleep(Integer.MAX_VALUE);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();

        new Thread(()->{
            ((Child) father).lock();
        }).start();
    }
}


class Father{


}

class Child extends Father{
    public void lock(){
        synchronized (this){
            System.out.println("获取Child lock成功");
        }
    }
}